package com.eastedu.repository.assignment;

import com.alibaba.fastjson.JSON;
import com.eastedu.entity.Entity;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;

import java.util.Random;

/**
 * The type Assignment base entity.
 * @author zhangzhishuai
 */
@Data
@MappedSuperclass
public class AssignmentBaseEntity implements Entity<Long> {
    @Id
    @Column(
            name = "id",
            columnDefinition = "bigint comment '主键'",
            nullable = false,
            updatable = false
    )
    private Long id;
    @Column(
            name = "create_time",
            columnDefinition = "bigint comment '创建时间'",
            nullable = false,
            updatable = false
    )
    private Long createTime;
    @Column(
            name = "update_time",
            columnDefinition = "bigint comment '更新时间'",
            nullable = false
    )
    private Long updateTime;


    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    /**
     * Init base entity.
     *
     * @return the base entity
     */
    public AssignmentBaseEntity init() {
        long nowTime = System.currentTimeMillis();
        this.id = new Random().nextLong();
        this.createTime = nowTime;
        this.updateTime = nowTime;
        return this;
    }
}
